package com.meilai.project.controller.web.business.media;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.business.media.MediaTypeDTO;
import com.meilai.project.entity.media.MediaType;
import com.meilai.project.service.business.media.MediaTypeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "媒体类型控制器")
@RestController
@RequestMapping("api/web/media/type")
public class WebMediaTypeController {

    @Autowired
    private MediaTypeService mediaTypeService;

    @GetMapping("/list")
    public CommonResult list(@RequestParam(value = "name", required = false) String name) {
        return new CommonResult().success(mediaTypeService.list(name));
    }

    @GetMapping("/detail")
    public CommonResult detail(@RequestParam(value = "id") Long id) {
        return new CommonResult().success(mediaTypeService.getById(id));
    }


    @GetMapping("/all")
    public CommonResult allList() {
        return new CommonResult().success(mediaTypeService.list());
    }

    @GetMapping("/allLevel1")
    public CommonResult allLevel1() {
        return new CommonResult().success(mediaTypeService.list(Wrappers.<MediaType>lambdaQuery().eq(MediaType::getPid, 0)));
    }

    @PutMapping("/edit")
    public CommonResult edit(@RequestBody MediaType mediaType) {
        return new CommonResult().success(mediaTypeService.edit(mediaType));
    }

    @PostMapping("/save")
    public CommonResult save(@RequestBody MediaTypeDTO dto) {
        return new CommonResult().success(mediaTypeService.save(dto));
    }

    @GetMapping("/type_list")
    public CommonResult typeList(@RequestParam(value = "media_type_id", required = false) Long media_type_id) {
        return new CommonResult().success(mediaTypeService.getTypeList(media_type_id));
    }
}
